library SelectFTCommand initializer init requires LegacySystem, PlayerSelectsHeroCommand, LegacyHumanAbilities

	private function NoAmmoFirebat takes nothing returns nothing
		local integer i = GetConvertedPlayerId(GetTriggerPlayer())
		if GetWidgetLife(udg_Hero[i])>0.405 then
			set udg_Reloading[i] = 1
			set udg_soundpath = "war3mapImported\\NoAmmo.wav"
		call PlaySoundPath.execute()
			call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 2.0, "|cfff3ad00ALICE|r : " + GetPlayerName(GetTriggerPlayer()) + " has run out of fuel." )
			call UnitAddAbility(udg_Hero[i],'A02H')
			call UnitRemoveAbility(udg_Hero[i],'A044')
		endif
	endfunction


	private function Trig_Player_Selects_FB_Conditions takes nothing returns boolean
		if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'H000' ) ) then
			return false
		endif
		return true
	endfunction

	private function Trig_Player_Selects_FB_Actions takes nothing returns nothing

		local unit u = GetTriggerUnit()
		local player p = GetOwningPlayer(u)
		local integer id = GetConvertedPlayerId(p)
		local trigger t

		call putUnit(p,"hero", u)

		call setPlayerDataInteger(p,"pistol_ammo",8)
		call setPlayerDataInteger(p,"pistol_type",0)
		call setPlayerDataBoolean(p,"pistol_reload",false)

		set udg_HeroAvailable[2] = udg_HeroAvailable[2] - 1
		set udg_PlayerIcon[id] = "ReplaceableTextures\\CommandButtons\\BTN_Unit_Firebat.blp"

			
		set udg_FuelEfficiency[id] = 1.0
		set udg_KillFactor[id] = 1.2
	  
		call AddPrimaryAmmo(u, 0, 800)
		call RegisterAmmoEmptyListener(u)
		
		set t = CreateTrigger()
		call TriggerRegisterPlayerStateEvent( t, p, PLAYER_STATE_RESOURCE_GOLD, EQUAL, 0.0 )
		call TriggerAddAction( t, function NoAmmoFirebat )

		call InitHero(u)
		set t = null
		set u = null
		set p = null
		
		if GetI("player mos", id) ==  3 then
			call ModifyHeroSkillPoints( u, bj_MODIFYMETHOD_ADD, 1 )
		endif
		
		if( udg_HeroAvailable[2] <= 0 ) then
			call DisableTrigger(GetTriggeringTrigger())
		endif

	endfunction

	private function init takes nothing returns nothing
		local trigger t
		set t = CreateTrigger(  )
		call TriggerRegisterEnterRectSimple( t, GetPlayableMapRect() )
		call TriggerAddCondition( t, Condition( function Trig_Player_Selects_FB_Conditions ) )
		call TriggerAddAction( t, function Trig_Player_Selects_FB_Actions )
	endfunction

endlibrary